package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventYwwczlBo;
import com.ruoyi.event.domain.vo.EventYwwczlVo;
import com.ruoyi.event.service.IEventYwwczlService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 药物维持治疗
 *
 * @author strongme
 * @date 2023-02-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/ywwczl")
public class EventYwwczlController extends BaseController {

    private final IEventYwwczlService iEventYwwczlService;

    /**
     * 查询药物维持治疗列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventYwwczlVo> list(EventYwwczlBo bo, PageQuery pageQuery) {
        return iEventYwwczlService.queryPageList(bo, pageQuery);
    }

    @PostMapping("query")
    public R<List<EventYwwczlVo>> query(@RequestBody EventYwwczlBo bo) {
        return R.ok(iEventYwwczlService.queryList(bo));
    }

    /**
     * 导出药物维持治疗列表
     */
    @Log(title = "药物维持治疗", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventYwwczlBo bo, HttpServletResponse response) {
        List<EventYwwczlVo> list = iEventYwwczlService.queryList(bo);
        ExcelUtil.exportExcel(list, "药物维持治疗", EventYwwczlVo.class, response);
    }

    /**
     * 获取药物维持治疗详细信息
     *
     * @param ywwczlId 主键
     */
    @GetMapping("/{ywwczlId}")
    public R<EventYwwczlVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long ywwczlId) {
        return R.ok(iEventYwwczlService.queryById(ywwczlId));
    }

    /**
     * 新增药物维持治疗
     */
    @Log(title = "药物维持治疗", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventYwwczlBo bo) {
        return toAjax(iEventYwwczlService.insertByBo(bo));
    }

    /**
     * 修改药物维持治疗
     */
    @Log(title = "药物维持治疗", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventYwwczlBo bo) {
        return toAjax(iEventYwwczlService.updateByBo(bo));
    }

    /**
     * 删除药物维持治疗
     *
     * @param ywwczlIds 主键串
     */
    @Log(title = "药物维持治疗", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ywwczlIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ywwczlIds) {
        return toAjax(iEventYwwczlService.deleteWithValidByIds(Arrays.asList(ywwczlIds), true));
    }
}
